import Api from '@/service/api/api';
import { request } from '../request';

/**
 * Login
 *
 * @param userName User name
 * @param password Password
 */
export function fetchLogin(userName: string, password: string) {
  return request<Api.Auth.LoginToken>({
    url: Api.Login,
    method: 'post',
    data: {
      username: userName,
      password,
      code: '',
      uuid: ''
    }
  });
}

/** Get user info */
export function fetchGetUserInfo() {
  return request<Api.Auth.UserInfo>({ url: Api.UserInfo });
}

/**
 * 退出登录
 */
export function logoutAction() {
  return request<any>({
    url: Api.Logout,
    method: 'get'
  });
}

/**
 * Refresh token
 *
 * @param refreshToken Refresh token
 */
export function fetchRefreshToken(refreshToken: string) {
  return request<Api.Auth.LoginToken>({
    url: '/auth/refreshToken',
    method: 'post',
    data: {
      refreshToken
    }
  });
}

/**
 * 查询更新日志
 *
 * @param params
 */
export function getVersionListAction(params: any) {
  return request<any>({
    url: Api.VersionList,
    method: 'get',
    params
  });
}

/**
 * 检查用户是否查看过更新日志
 *
 * @param params
 */
export function checkVersionUserReviewAction(params: any) {
  return request<any>({
    url: Api.CheckVersionUserReview,
    method: 'get',
    params
  });
}

/**
 * 新增版本迭代用户查看记录
 *
 * @param params
 */
export function addUserReviewVersionAction(params: any) {
  return request<any>({
    url: Api.VersionAdd,
    method: 'post',
    data: params
  });
}
